$(document).ready(function() {
    $('.ipt_cell input.slt, .ipt_cell input.date').each(function() {
        $(this).after('<i></i>');
        $(this).prop('readonly', true)
    });
});

/*获取地址栏中指定参数的值*/
function request(paras) {
    var url = location.href;
    var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
    var paraObj = {}
    for (i = 0; j = paraString[i]; i++) {
        paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=") + 1, j.length);
    }
    var returnValue = paraObj[paras.toLowerCase()];
    if (typeof(returnValue) == 'undefined') {
        return "";
    } else {
        return decodeURI(returnValue);
    }
}

/*判断是否为空*/
function isNull(arg1) {
    return !arg1 && arg1 !== 0 && typeof arg1 !== "boolean" ? true : false;
}

function getWinWidth() {
    return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth || 0
}

function getWinHeight() {
    return window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || 0
}

function getWinScrollHeight() {
    return document.documentElement.scrollTop || document.body.scrollTop
}
//取得cookie  
function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';'); //把cookie分割成组  
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i]; //取得字符串  
        while (c.charAt(0) == ' ') { //判断一下字符串有没有前导空格  
            c = c.substring(1, c.length); //有的话，从第二位开始取  
        }
        if (c.indexOf(nameEQ) == 0) { //如果含有我们要的name  
            return unescape(c.substring(nameEQ.length, c.length)); //解码并截取我们要值  
        }
    }
    return false;
}
//清除cookie  
function clearCookie(name) {
    setCookie(name, "", -1);
}

//设置cookie  
function setCookie(name, value, seconds) {
    seconds = seconds || 0; //seconds有值就直接赋值，没有为0，这个根php不一样。  
    var expires = "";
    if (seconds != 0) { //设置cookie生存时间  
        var date = new Date();
        date.setTime(date.getTime() + (seconds * 1000));
        expires = "; expires=" + date.toGMTString();
    }
    document.cookie = name + "=" + escape(value) + expires + "; path=/"; //转码并赋值  
}
//获取当前时间并格式化
function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate + " " + date.getHours() + seperator2 + date.getMinutes() + seperator2 + date.getSeconds();
    return currentdate;
}
//截取字符串
function cutword(str, n, point) {
    if (str.length > n) {
        str = str.substr(0, n);
        if (point)
            str = str + "...";
    }
    return str;
}
//格式化字符串，将每一行算为一个段落
function replaceStr(introStr) {
    var newStr = introStr.replace(/[\r\n]/g, "</p><p>");
    newStr += "<p>";
    return newStr;
}

function tiper(word, color, time) {
    $('.tiper').remove();
    var html = ''
    if (color == "green")
        html += '<div class="tiper green">' + word + '</div>';
    else if (color == "blue")
        html += '<div class="tiper blue">' + word + '</div>';
    else
        html += '<div class="tiper">' + word + '</div>';
    $('body').prepend(html);
    setTimeout(function() {
        $('.tiper').fadeOut(500);
    }, time ? time : 3000);
}

function myGet(url) {
    var result;
    jQuery.ajax({
        type: "get",
        async: false,
        url: url,
        success: function(json) {
            result = json;
        }
    });
    return result;
}

function myPost(url, data) {
    var result;
    jQuery.ajax({
        type: "post",
        async: false,
        url: url,
        data: data,
        success: function(json) {
            result = json;
        }
    });
    return result;
}
//图片未找到时用默认图片代替
function nofind(obj, type) {
    if (type == 1)
        obj.src = "images/cover_mid.gif";
    else
        obj.src = "cover_big.gif";
    obj.onerror = null;
}

function formatDate(now) {
    var newDate = new Date();
    newDate.setTime(now * 1000);
    Date.prototype.format = function(format) {
        var date = {
            "M+": this.getMonth() + 1,
            "d+": this.getDate(),
            "h+": this.getHours(),
            "m+": this.getMinutes(),
            "s+": this.getSeconds(),
            "q+": Math.floor((this.getMonth() + 3) / 3),
            "S+": this.getMilliseconds()
        };
        if (/(y+)/i.test(format)) {
            format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
        }
        for (var k in date) {
            if (new RegExp("(" + k + ")").test(format)) {
                format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
            }
        }
        return format;
    }
    return newDate.format('yyyy-MM-dd hh:mm:ss');
}
Date.prototype.format = function(format) {
    var o = {
        "M+": this.getMonth() + 1, //month
        "d+": this.getDate(), //day
        "h+": this.getHours(), //hour
        "m+": this.getMinutes(), //minute
        "s+": this.getSeconds(), //second
        "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
        "S": this.getMilliseconds() //millisecond
    }
    if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
        (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(format))
            format = format.replace(RegExp.$1,
                RegExp.$1.length == 1 ? o[k] :
                ("00" + o[k]).substr(("" + o[k]).length));
    return format;
}

function get_os() {
    var u = navigator.userAgent.toLowerCase();
    if (u.indexOf('android') > -1 || u.indexOf('linux') > -1) {
        return 'android';
    } else if (u.indexOf('iphone') > -1) {
        //苹果手机
        return '苹果手机';
    } else if (u.indexOf('windows phone') > -1) {
        //winphone手机
        return '微软手机';
    }
}

// loading 加载
function loading_show() {
    $('body').prepend('<div class="loading"></div>');
    shadow_show('.2');
}
function loading_hide(time) {    
    setTimeout(function() {
        $('.loading').remove();
        shadow_hide();        
    },time);    
}

// shadow 遮罩层
function shadow_show(opacity) {
    $('body').prepend('<div class="shadow"></div>');
    $('.shadow').css('opacity', opacity);
}
function shadow_hide() {
    $('.shadow').remove();
}


//写cookies
function setCookie(name, value,Days) {
    var exp = new Date();
    exp.setTime(exp.getTime() + Days * 1 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}
// 读取cookies
function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg))
        return unescape(arr[2]);
    else
        return null;
}

// function zoom_img(obj) {
//     var src = obj.attr('src');
//     var w = obj.css('width');
//     var h = obj.css('height');
//     var html = '<img src="'+src+'" alt="" style="position:absolute; z-index:1000; width:100%; left: 0; top:50%; margin-top:-'+(h/2)+'px" /><div style=" position:absolute; z-index:500; left: 0; top: 0; background:#000;opacity:0.8;"></div>';
//     $('body').append(html);
// }
// $('.zoom').click(function(){
//     zoom_img($(this));
// })